package eu.webhib.extgui.utils;

import eu.webhib.frmwrk.jsf.exception.FatalApplException;
import eu.webhib.frmwrk.persistence.PersistenceMngr;
import org.apache.log4j.Logger;

/**
 * Wrapper/Closure for catching exceptions from method invocations called
 * directly from the GUI view
 */
public abstract class GuiRequestClosure {

   private static final Logger log = Logger.getLogger(GuiRequestClosure.class);

   abstract protected void run();

   public void start() throws FatalApplException {
      try {
         run();
         PersistenceMngr.commitTransaction();
      } catch (javax.persistence.OptimisticLockException t) {
         log.info("GuiRequestClosure - OptimisticLock");
         /** for now no response for user at GUI */
         PersistenceMngr.rollbackTransaction();
      } catch (javax.persistence.PersistenceException t) {
         log.info("GuiRequestClosure - PersistenceException");
         /** for now no response for user at GUI */
         PersistenceMngr.rollbackTransaction();
      }
   }
}
